package com.strongwell.awe.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.strongwell.awe.dao.CmsArticleDao;
import com.strongwell.awe.model.CmsArticleEntity;
import com.strongwell.awe.service.CmsArticleService;



@Service("cmsArticleServiceImpl")
public class CmsArticleServiceImpl implements CmsArticleService {
	@Autowired
	private CmsArticleDao cmsArticleDao;
	
	@Override
	public CmsArticleEntity queryObject(Long id){
		return cmsArticleDao.queryObject(id);
	}
	
	@Override
	public List<CmsArticleEntity> queryList(Map<String, Object> map){
	    if (map.get("id")!=null && map.get("id").toString()!=""){
           if (Integer.parseInt(map.get("id").toString())>0) {
               return cmsArticleDao.queryListInfo(map);
           }else{
               return cmsArticleDao.queryList(map);
           }
       }else {
           return cmsArticleDao.queryList(map);
       }
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){

		return cmsArticleDao.queryTotal(map);
	}
	

	
	@Override
	public int delete(Long id){
		return cmsArticleDao.delete(id);
	}
	
	@Override
	public int deleteBatch(Long[] ids){
		return cmsArticleDao.deleteBatch(ids);
	}

    @Override
    public void save(CmsArticleEntity cmsarticle){
        Date date=new Date();
        cmsarticle.setCreateTime(date);
			cmsArticleDao.save(cmsarticle);
    }

    @Override
    public int update(CmsArticleEntity cmsarticle){
        Date date=new Date();
        cmsarticle.setUpdateTime(date);
        return cmsArticleDao.update(cmsarticle);
    }

    public int delById(Long id){
        Date date=new Date();
			CmsArticleEntity cmsarticle= new CmsArticleEntity();
        cmsarticle.setId(id);
        cmsarticle.setDeleteTime(date);
        return cmsArticleDao.update(cmsarticle);
    }

    public int delPatch(String  cmsarticlestr){
        String[] strs = cmsarticlestr.split(",");
        if(strs!=null&&strs.length>0){
            for (String str : strs) {
                delById(Long.parseLong(str));
            }
        }
        return 0;
    }

    @Override
    public CmsArticleEntity queryName(String name){
        return cmsArticleDao.queryName(name);
    }

    @Override
    public List<CmsArticleEntity> queryArticleList(int num){
        return cmsArticleDao.queryArticleList(num);
    }

    @Override
    public List<CmsArticleEntity> queryListInfo(Long id,Map<String, Object> map){
	    map.put("id",id);
        return cmsArticleDao.queryListInfo(map);
    }

    @Override
    public List<CmsArticleEntity> queryArticle(String module){
        return cmsArticleDao.queryArticle(module);
    }

}
